package hu.rsc.feeds.client.util;

import hu.rsc.feeds.client.data.DictionaryDto;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.XMLParser;

public class DictionaryReader {

    public static DictionaryDto getDictionary(String content) {

	HashMap<String, String> properties = new HashMap<String, String>();
	DictionaryDto dto = new DictionaryDto(properties);
	Document document = XMLParser.parse(content);
	try {

	    Element root = document.getDocumentElement();
	    for (int i = 0; i < root.getChildNodes().getLength(); i++) {
		try {
		    Element node = (Element) root.getChildNodes().item(i);
		    properties.put(node.getNodeName(), node.getFirstChild().toString());
		} catch (Exception e2) {

		}
	    }
	} catch (Exception e) {
	    return null;
	}
	return dto;
    }

    public static List<String> getTips(String language, String content) {

	List<String> tips = new ArrayList<String>();
	Document document = XMLParser.parse(content);
	try {

	    Element root = document.getDocumentElement();
	    for (int i = 0; i < root.getChildNodes().getLength(); i++) {
		try {
		    Element node = (Element) root.getChildNodes().item(i);
		    tips.add(node.getFirstChild().toString());
		} catch (Exception e2) {

		}
	    }
	} catch (Exception e) {
	    return null;
	}
	return tips;
    }
}
